#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//分配、释放内存

int main(){
    char name[100];//固定大小的数组，无法改变
    char *description;//char指针，可以等同于不定大小的char description[]

    //分配指定大小内存,强转为(char *)类型
    description = (char *)malloc(200 * sizeof(char));
    if (description == NULL){
        perror("malloc failed");
    }else{
        strcpy(description, "this is a string.\n");
    }

    printf("%s", description);

    //重新分配指定内存大小
    description = (char *)realloc(description, 100 * sizeof(char));
    if (description == NULL){
        perror("realloc failed");
    }else{
        strcpy(description, "this is a realloc string.\n");
    }
    
    printf("%s", description);

    free(description);
    
}